package cn.mayaslight.wechat.api;

import cn.mayaslight.common.annotation.HttpWithParam;
import cn.mayaslight.common.param.IParamIn;
import cn.mayaslight.common.springbean.APICaller;
import cn.mayaslight.wechat.api.bean.Token;


public class TokenAPI extends BaseAPI{
	
	/**
	 * 获取AccessToken类
	 * @param appid
	 * @param secret
	 * @param isQy
	 * @return
	 */
	public static Token token(final String appid, final String secret, final boolean isQy){
		return APICaller.call(isQy ? new IParamIn() {
			
			@HttpWithParam("corpid")
			private String _appid = appid;
			
			@HttpWithParam("corp_secret")
			private String _secret = secret;
			
			@HttpWithParam("grant_type")
			private String _grantType = "client_credential";
			
			public String getApiKey() {
				// TODO Auto-generated method stub
				return null;
			}
		} : new IParamIn() {
			
			@HttpWithParam("appid")
			private String _appid = appid;
			
			@HttpWithParam("secret")
			private String _secret = secret;
			
			@HttpWithParam("grant_type")
			private String _grantType = "client_credential";
			
			public String getApiKey() {
				return APICaller.HTTP_URL_GET_PREFIX + APICaller.HTTP_URL_JSON_PREFIX + BASE_URI + "/cgi-bin/token";
			}
		}, Token.class);
	}
	
	public static void main(String[] args) {
		Token token = TokenAPI.token("wx849965a946c29928", "1046f010ea002d3ff106b093331eadb8", false);
		System.out.println(token.getErrcode() + "***************" + token.getAccess_token());
	}

}
